/*
 * Dialogue.hpp
 *
 *  Created on: Sep 7, 2013
 *      Author: jason
 */

#ifndef DIALOGUE_HPP_
#define DIALOGUE_HPP_

#include <unordered_map>
#include <string>
#include <vector>
#include <SFML/Graphics.hpp>
#include "../Common.hpp"
#include "../InputEngine.hpp"
#include "../GUI/GUIManager.hpp"
#include "../Objects/Characters.hpp"

namespace OForce_Mode {

const int INCREMENT_LINE = -1;
const int END_DIALOGUE   = -2;

class Dialogue {
public:
	Dialogue(int id);
	~Dialogue() {}
	int getDialogueID() {return mId;}
	int getSpeaker(int line) {return speakers[line];}
	void addLine(std::string text, int speakerID);
	void addLine(std::string text, int speakerID, int nextLineID);
	void beginDialogue(int line);
	void draw();
	void setSpeakerName(std::string name) {mName = name;}
	void setPortraitFile(std::string filepath) {portraitFileName = filepath;}
	std::string getLineText(int line) {return lines[line];}
	int getNextLine(int line_number) {return nextLineIDs[line_number];}
	int getNumLines() { return lines.size(); }
	int getTimesSeen() {return timesSeen;}
	void incrementTimesSeen() {timesSeen++;}
private:
	int mId;
	int currentLine;
	int timesSeen;
	std::string mName;
	std::vector< std::string > lines;
	std::string portraitFileName;
	std::vector<int> speakers;
	std::vector<int> nextLineIDs;
	sf::Font font;
	sf::Image dialogueImage;
	sf::Texture dialogueTexture;
	sf::Sprite dialogueSprite;
	sf::Text dialogueText;
	sf::Text name;
}; // Dialogue

enum DIALOGUE_STATE {LINE, EMOTE, ACTION, OPTION};

class DialogueManager {
public:
	DialogueManager();
	~DialogueManager();
	void draw();
	void update();
	void addDialogue(Dialogue* dialogue);
	void startDialogue(int ID);
	void processDialogueEvents();
	void endDialogue();
	Dialogue *getDialogue(int ID);
	Dialogue *getCurrentDialogue() {return currentDialogue;}
	void beginLine();
	bool finishedTyping() {return dialogueWindow.finishedTyping();}
	void hurry();
private:
	void updateLine();
	void updateEmote();
	void updateAction();
	void updateOption();
	int currentLine;
	float coolDown;
	float timer;
	DIALOGUE_STATE currentState;
	std::unordered_map<int, Dialogue *> dialogueMap;
	Dialogue *currentDialogue;
	OForce_Input::InputEngine *mInput;
	OForce_UI::DialogueWindow dialogueWindow;
	OForce_Object::DIRECTION oldDir;
};

}


#endif /* DIALOGUE_HPP_ */
